package plugins.lxfa.mainMenuBottom
{
	import caurina.transitions.Tweener;
	
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.utils.clearInterval;
	import flash.utils.setInterval;
	
	public class Ad extends Sprite
	{
		private var jsqint:int=0;
		
		
		private var hjMC:SimpleButton=new  AdHuoJu();
		private var ycMC:SimpleButton=new AdYuChai();
		
		private var ad1req:URLRequest=new URLRequest("http://www.yuchai.com/lib/index/");
		private var ad2req:URLRequest=new URLRequest("http://www.gxtorch.com.cn/");
		private var state:int=1;                     //0表示正在显示火炬，1表示正在显示玉柴
		private var temp:SimpleButton;
		private var key:int;
		public function Ad() {
			init();
		}
		private function init():void
		{
			hjMC.x=((900)/2-(hjMC.width)/2);
			hjMC.y=ycMC.y=565;
			ycMC.x=((900)/2-(ycMC.width)/2);
			this.addEventListener(MouseEvent.MOUSE_DOWN,open_url);
			this.addChild(hjMC);
			this.addChild(ycMC);
			hjMC.alpha=0;
			ycMC.alpha=0;
			temp=ycMC;
			show();
		}
		/**
		 * 打开链接
		 */ 
		private function open_url (e:MouseEvent):void{
			if(temp==hjMC)
			{
				navigateToURL(ad2req,"_blank");
			}else
			{
				navigateToURL(ad1req,"_blank");
			}
			
		}
		/**
		 * 渐渐的显示出来
		 */ 
		private function show():void
		{
			Tweener.addTween(temp,{alpha:1,time:speed,onComplete:function():void{
			    stay();
			}});
		}
		/**
		 * 停留在那里
		 */ 
		private function stay():void
		{
			key=setInterval(hide, 3000);
		}
		private const speed:int=2;//渐变的速度
		/**
		 * 渐渐的隐藏起来
		 */ 
		private function hide():void
		{
			clearInterval(key);
			Tweener.addTween(temp,{alpha:0,time:speed,onComplete:function():void{
				if(temp==hjMC)
				{
					temp=ycMC;
				}else
				{
					temp=hjMC;
				}
			    show();
			}});
		}
	}
}